<?php
$_GET['type'] = empty($_GET['type']) ? '' : intval($_GET['type']);
$orderby = get_major_key(array('id' => 'DESC'));
$oNotice = new Notice();

if(!empty($_GET['btnExport'])){	// 导出
	$list = $oNotice->get_list('*', $_GET, $orderby, $__page, $__pagesize, $offset = 0);
	if(!empty($list['list']) && is_array($list['list'])){
		$data = array();
		foreach($list['list'] as $row){
			$row['time'] = ftime($row['time']);
			$data[] = $row;
		}
		$headers = array(
			'id'		=> array('title' => 'ID',		'width' => '6'),
			'type'		=> array('title' => '类型', 		'width' => '12.5'),
			'msg'		=> array('title' => '消息', 		'width' => '12.5'),
			'time'		=> array('title' => '时间', 		'width' => '18'),
			'read'		=> array('title' => '已读', 		'width' => '18'),
		);
		if($list['total'] > 5000){	// 导出超过5000时用CSV
			export_csv($data, $headers, '_E_消息_'.date('Ymd_His').'.csv');
		}else{
			$oExcel = new Excel();
			$oExcel->export($headers, $data, '_E_消息_'.date('Ymd_His').'.xlsx');
		}
	}
	exit;
}

$list = $oNotice->get_list('*', $_GET, $orderby, $__page, $__pagesize);
if(!empty($list['list']) && is_array($list['list'])){
	
	// 主键排序字段
	make_major_key_options(array(
		'id'	=> '消息编号',
		'time'	=> '添加时间',
	));

	foreach($list['list'] as $key => $row){
		switch($row['type']){
			case '101':
				$row['type'] = '新订单';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个新订单' : $row['msg'];
				$row['url'] = "./m.php?frm=order&mdl=order&do=edit&id={$row['target']}";
				break;
			case '102':
				$row['type'] = '订单正在付款';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个订单正在付款' : $row['msg'];
				$row['url'] = "./m.php?frm=order&mdl=order&do=edit&id={$row['target']}";
				break;
			case '103':
				$row['type'] = '订单付款成功';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个订单付款成功' : $row['msg'];
				$row['url'] = "./m.php?frm=order&mdl=order&do=edit&id={$row['target']}";
				break;
			case '104':
				$row['type'] = '订单用户已收货';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个订单用户已收货' : $row['msg'];
				$row['url'] = "./m.php?frm=order&mdl=order&do=edit&id={$row['target']}";
				break;
			case '105':
				$row['type'] = '订单有新的评价';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个订单有新的评价' : $row['msg'];
				$row['url'] = "./m.php?frm=order&mdl=order&do=edit&id={$row['target']}";
				break;
			case '201':
				$row['type'] = '商品缺货';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个商品缺货' : $row['msg'];
				$row['url'] = "./m.php?frm=goods&mdl=goods&do=edit&id={$row['target']}";
				break;
			case '202':
				$row['type'] = '商品被收藏';
				$row['msg'] = empty($row['msg']) ? '有<b>1</b>个商品被收藏' : $row['msg'];
				$row['url'] = "./m.php?frm=goods&mdl=goods&do=edit&id={$row['target']}";
				break;
		}
		$row['time'] = ftime($row['time']);
		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['pagelist'] = $list['pagelist'];
}
?>